package cn.sccl.dirms.enumConst;

import java.io.Serializable;

/**
 * 操作类型
 * Created by 贺 强 on 2016/3/18.
 */
public enum OperationTypeEnum implements Serializable {
    SIGN_ON("登录", 1),
    SIGN_OUT("登出", 2),
    NONE("未定义", 9999);

    private String cnName;

    private Integer value;

    private OperationTypeEnum() {

    }

    private OperationTypeEnum(String cnName, Integer value) {
        this.cnName = cnName;
        this.value = value;
    }

    public String getCnName() {
        return cnName;
    }

    public Integer getValue() {
        return value;
    }

    //根据值获取枚举对象的名称，如果不存在该枚举，返回空串
    public static String getNameByValue(Integer value){
        for(OperationTypeEnum e : OperationTypeEnum.values()){
            if(value.equals(e.getValue())){
                return e.getCnName();
            }
        }
        return "";
    }

    public static OperationTypeEnum getEnumByValue(Integer value){
        for(OperationTypeEnum e : OperationTypeEnum.values()){
            if(value.equals(e.getValue())){
                return e;
            }
        }
        return null;
    }
}
